package com.test.fundible.fundible_05_process;

import static com.test.fundible.fundible_00_utils.FundibleUtil.startLoading;
import static com.test.fundible.fundible_00_utils.FundibleUtil.stopLoading;
import static com.test.fundible.fundible_00_utils.FundibleConfigs.PermissionCode_Camera;
import static com.test.fundible.fundible_00_utils.FundibleConfigs.Process_Step_Account;
import static com.test.fundible.fundible_00_utils.FundibleConfigs.Process_Step_Contact;
import static com.test.fundible.fundible_00_utils.FundibleConfigs.Process_Step_Ocr;
import static com.test.fundible.fundible_00_utils.FundibleConfigs.Process_Step_Personal;
import static com.test.fundible.fundible_00_utils.FundibleConfigs.Process_Step_Sefie;
import static com.test.fundible.fundible_00_utils.FundibleConfigs.Process_Step_Work;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.PickVisualMediaRequest;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.test.fundible.R;
import com.test.fundible.fundible_00_utils.Kind_fundibleTip_fundibleDialog;
import com.test.fundible.fundible_00_utils.Loading_fundibleDialog;
import com.test.fundible.fundible_06_loan_apply.LoanApplyActivity;
import com.test.fundible.fundible_05_process.widget.BaseProc_fundibleessWid_fundiblegetManager;
import com.test.fundible.fundible_06_loan_apply.LoanApplyActivity_OldUser;
import com.test.fundible.fundible_10_vip.Pers_fundibleonalIn_fundiblefo;
import com.test.fundible.fundible_00_customer_service.Customer_fundibleServiceDialog;
import com.test.fundible.fundible_00_http.OkHttpUtil;
import com.test.fundible.fundible_00_utils.image_fundible.Image_fundibleConvert;
import com.test.fundible.fundible_05_process.widget.BindAcco_fundibleuntViewM_fundibleanager_Fr;
import com.test.fundible.fundible_05_process.widget.DateS_fundibleelectVie_fundiblewManager;
import com.test.fundible.fundible_05_process.widget.Face_fundibleViewM_fundibleanager;
import com.test.fundible.fundible_05_process.widget.Ge_fundiblenderSe_fundiblelectViewManager;
import com.test.fundible.fundible_05_process.widget.Input_fundibleViewMan_fundibleager;
import com.test.fundible.fundible_05_process.widget.OcrVie_fundiblewMana_fundibleger;
import com.test.fundible.fundible_05_process.widget.Sele_fundiblectViewMana;
import com.test.fundible.fundible_00_utils.FundibleConfigs;
import com.test.fundible.fundible_00_utils.FundibleUtil;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

import pub.devrel.easypermissions.AppSettingsDialog;
import pub.devrel.easypermissions.EasyPermissions;

public class Pro_fundiblecessAct_fundibleivity extends AppCompatActivity implements EasyPermissions.RationaleCallbacks,EasyPermissions.PermissionCallbacks{

    private LinearLayout parentGroupLayout;
    private TextView nextBtn;

    private TextView titleTv;
    private View topView;
    private ImageView stepLogoIv;
    private TextView stepTitleTv,stepDescTv;
    private LinearLayout topGroupLayout;

    private Proce_fundiblessInf_fundibleo_Step step_fundible;

    private final ArrayList<BaseProc_fundibleessWid_fundiblegetManager> processWidgetManagers_fundible = new ArrayList<>();

    private BindAcco_fundibleuntViewM_fundibleanager_Fr bindAccountViewManager_fundible;//法语区绑卡组件
    private OcrVie_fundiblewMana_fundibleger ocrViewManager_fundible;//Ocr组件
    private Face_fundibleViewM_fundibleanager faceViewManager_fundible;//Face组件

    private String path_fundible;

    private Runnable nextBtnRunnable_fundible;

    private String currentStepName = "";

    private final String[] userNames = new String[]{"","",""};

    private static String page_fundible = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fundible_process);
        //tag2024
//        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);

        currentStepName = Pro_fundiblecessIn_fundiblefo.getInstance_fundible().getStepName_fundible(0);

        if (!TextUtils.isEmpty(currentStepName)) page_fundible = currentStepName.toUpperCase();
        else page_fundible = getClass().getSimpleName().toUpperCase();

        findViewById(R.id.afp2_ib_back).setOnClickListener(v -> onBackPressed());
        findViewById(R.id.afp2_ib_customerservice).setOnClickListener(v -> new Customer_fundibleServiceDialog(this).show());

        parentGroupLayout = findViewById(R.id.afp2_layout_group);
        nextBtn = findViewById(R.id.afp2_btn_continue);
        titleTv = findViewById(R.id.afp2_tv_title);
        topView = findViewById(R.id.afp2_view_top);
        stepLogoIv = findViewById(R.id.afp2_iv_step_logo);
        stepTitleTv = findViewById(R.id.afp2_tv_step_title);
        stepDescTv = findViewById(R.id.afp2_tv_step_desc);
        topGroupLayout = findViewById(R.id.afp2_layout_top_group);

        step_fundible = Pro_fundiblecessIn_fundiblefo.getInstance_fundible().getStep_fundible(0);
        path_fundible = step_fundible == null ? "": step_fundible.getApiUrl_fundible();

        //next
        nextBtn.setOnClickListener(v -> {
            OkHttpUtil.getInstance_fundible().uploadEventPoint(page_fundible,"SAVE_CLICK","");
            if (step_fundible == null||TextUtils.isEmpty(path_fundible)) {
                onBackPressed();
                return;
            }
            if (nextBtnRunnable_fundible !=null) nextBtnRunnable_fundible.run();
        });

        initProcessStep();

    }

    //初始化流程步骤框架
    @SuppressLint("SetTextI18n")
    private void initProcessStep(){

        //Ocr和人脸流程直接添加
        if (currentStepName.equalsIgnoreCase(Process_Step_Ocr)){
            topView.setVisibility(View.GONE);
            initOcrProcess_fundible(parentGroupLayout);
            titleTv.setText(getString(R.string.ocr_title));
            return;
        }else if (currentStepName.equalsIgnoreCase(Process_Step_Sefie)){
            topView.setVisibility(View.GONE);
            initFaceProcess_fundible(parentGroupLayout);
            titleTv.setText(getString(R.string.face_title));
            nextBtn.setText(getString(R.string.face_btn));
            return;
        }

        ArrayList<String> allSteps = Pro_fundiblecessIn_fundiblefo.getInstance_fundible().getAllSteps_fundible();
        ArrayList<String> steps = Pro_fundiblecessIn_fundiblefo.getInstance_fundible().getSteps_fundible();

        if (step_fundible!=null){
            String num = (allSteps.indexOf(currentStepName)+1) + ".";
            stepTitleTv.setText(num+step_fundible.getTitle_fundible());
            stepDescTv.setText(step_fundible.getText_fundible());
            stepLogoIv.setBackgroundResource(getStepImg(currentStepName));
        }

        for (String step:allSteps){
            View view = View.inflate(this,R.layout.view_step,null);
            View bg = view.findViewById(R.id.vs_bg);
            if (!steps.contains(step) || steps.indexOf(step)==0)bg.setBackgroundResource(R.drawable.bg_step_light);
            else bg.setBackgroundResource(R.drawable.bg_step_gray);
            view.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT,1));
            topGroupLayout.addView(view);
        }

        for (int i=0;i<allSteps.size();i++){

            String stepName = allSteps.get(i);

            if (!steps.contains(stepName)){//已完成流程
                //添加已完成流程展示
                View item = View.inflate(this,R.layout.view_fundible_process_item_finish,null);
                TextView stepNameTv = item.findViewById(R.id.vfpif_tv_step_name);
                stepNameTv.setText(Pro_fundiblecessIn_fundiblefo.getInstance_fundible().getStepTitle_fundible(i));
                parentGroupLayout.addView(item);
            }else if (stepName.equalsIgnoreCase(currentStepName)){//当前流程
                //添加当前流程展示
                View item = View.inflate(this,R.layout.view_process_fundible_item_current,null);
                TextView stepNameTv = item.findViewById(R.id.vpfic_tv_step_name);
                stepNameTv.setText(Pro_fundiblecessIn_fundiblefo.getInstance_fundible().getStepTitle_fundible(i));
                initProcessItems_fundible(item.findViewById(R.id.vpfic_layout_group));
                parentGroupLayout.addView(item);
            }else {//后续流程
                //添加后续流程展示
                View item = View.inflate(this,R.layout.view_fundible_process_item,null);
                TextView stepNameTv = item.findViewById(R.id.vfpi_tv_step_name);
                stepNameTv.setText(Pro_fundiblecessIn_fundiblefo.getInstance_fundible().getStepTitle_fundible(i));
                parentGroupLayout.addView(item);
            }

        }

    }

//-----------------------Old-------------------------------
    /**
     * 初始化流程
     */
    @SuppressLint("SetTextI18n")
    private void initProcessItems_fundible(LinearLayout groupLayout){
        if (step_fundible == null) {
            onBackPressed();
            return;
        }

        //根据流程类型分别处理
        switch (currentStepName){
            case FundibleConfigs.Process_Step_Contact://联系人流程
                initContactProcess_fundible(groupLayout);
                break;
            case FundibleConfigs.Process_Step_Account://绑卡流程
                if (FundibleUtil.isFrench_fundible()){//法语区绑卡流程
                    initBindAccountProcess_Fr_fundible(groupLayout);
                    startLoading(this,"");
                    OkHttpUtil.getInstance_fundible().fetchWalletAccountList_fr(this::onFetchFrAccountListResponse_fundible);
                    break;
                }
            default://普通流程
                initNormalProcess_fundible(groupLayout);
        }

    }

    /**
     * 普通流程
     */
    private void initNormalProcess_fundible(LinearLayout groupLayout){

        View group2View = View.inflate(this,R.layout.view_fundible_item_bg_fundible_group,null);
        LinearLayout group2Layout = group2View.findViewById(R.id.vibg_layout_group);

        for (int i = 0; i< step_fundible.getDataListSize_fundible(); i++){
            Proces_fundiblesIn_fundiblefo_Data data = step_fundible.getProcessData_fundible(i);
            if (data==null) continue;
            addInputView_fundible(data,null,group2Layout);
        }

        //数据上报处理
        nextBtnRunnable_fundible = () -> {

            for (BaseProc_fundibleessWid_fundiblegetManager processWidgetManager: processWidgetManagers_fundible){
                if (!processWidgetManager.checkI_fundiblenput()){
                    new Kind_fundibleTip_fundibleDialog(this,
                            getString(R.string.kind_tips_process_info_fill),
                            getString(R.string.ok),
                            null).show();
                    return;
                }
            }

            TreeMap<String,String> dataMap = new TreeMap<>();

            for (BaseProc_fundibleessWid_fundiblegetManager baseInfoInputViewManager: processWidgetManagers_fundible){

                Proces_fundiblesIn_fundiblefo_Data data = baseInfoInputViewManager.getDa_fundibleta();
                if (data==null) continue;

                //地址联动模块
//                if (data.getAction_fundible().equalsIgnoreCase(FundibleConfigs.Data_Action_AddressPick_fundible)){
//                    //坦桑尼亚
//                    if (FundibleUtil.isTanzan_fundible()){
//                        if (!(baseInfoInputViewManager instanceof AddressPickViewManager_Tanzan_fundible)) continue;
//                        AddressPickViewManager_Tanzan_fundible addressPickTanzanManager = (AddressPickViewManager_Tanzan_fundible) baseInfoInputViewManager;
//                        dataMap.put(data.getParamName_fundible(),addressPickTanzanManager.getState_fundible().trim());
//                        dataMap.put(data.getParamNameCity_fundible(),addressPickTanzanManager.getCity_fundible().trim());
//                    }
//                }
                //常规模块
                else dataMap.put(data.getParamName_fundible(),baseInfoInputViewManager.getInp_fundibleut().trim());

            }
            startLoading(this,"");
            OkHttpUtil.getInstance_fundible().uploadUserPrcsInfo(
                    path_fundible,dataMap,
                    () -> {
                        for (String k:dataMap.keySet()){
                            String v = dataMap.get(k);
                            extractPersonalInfo(k,v);
                        }
                        onSubmitInfoResponse_fundible();
                    });

        };

        groupLayout.addView(group2View);
    }

    /**
     * 联系人流程
     */
    @SuppressLint("InflateParams")
    private void initContactProcess_fundible(LinearLayout groupLayout){

        View group2View = View.inflate(this,R.layout.view_fundible_item_bg_fundible_group,null);
        LinearLayout group2Layout = group2View.findViewById(R.id.vibg_layout_group);

        for (int i = 0; i< step_fundible.getExtDataListSize_fundible(); i++){
            Proces_fundiblesIn_fundiblefo_Data data = step_fundible.getExtProcessData_fundible(i);
            if (data==null) continue;
            addInputView_fundible(data,null,group2Layout);
        }

        if (step_fundible.getItemCount_fundible()<=0) return;

        //添加一组联系人输入控件
        if (step_fundible.getExtDataListSize_fundible()>0) groupLayout.addView(group2View);
        //重新初始化一组新的联系人输入控件
        group2View = View.inflate(this,R.layout.view_fundible_item_bg_fundible_group,null);
        group2Layout = group2View.findViewById(R.id.vibg_layout_group);

        int count = 0;

        while (count< step_fundible.getItemCount_fundible()){//联系人数量
            for (int i = 0; i< step_fundible.getDataListSize_fundible(); i++){
                Proces_fundiblesIn_fundiblefo_Data data = step_fundible.getProcessData_fundible(i);
                if (data==null) continue;
                addInputView_fundible(data, step_fundible.getRelationShips_fundible(count),group2Layout);
            }

            //添加一组联系人输入控件
            groupLayout.addView(group2View);

            if (++count < step_fundible.getItemCount_fundible()){
                //重新初始化一组新的联系人输入控件
                group2View = View.inflate(this,R.layout.view_fundible_item_bg_fundible_group,null);
                group2Layout = group2View.findViewById(R.id.vibg_layout_group);
            }else break;
        }

        //数据上报处理
        nextBtnRunnable_fundible = () -> {

            TreeMap<String,String> dataMap = new TreeMap<>();

            ArrayList<String> relashipList = new ArrayList<>();
            ArrayList<String> nameList = new ArrayList<>();
            ArrayList<String> phoneList = new ArrayList<>();

            for (BaseProc_fundibleessWid_fundiblegetManager baseInfoInputViewManager: processWidgetManagers_fundible){

                Proces_fundiblesIn_fundiblefo_Data data = baseInfoInputViewManager.getDa_fundibleta();
                if (data==null) continue;
                switch (data.getAction_fundible()){

                    case FundibleConfigs.Data_Act_fundibleion_Contact_Relation:
                        relashipList.add(((Sele_fundiblectViewMana)baseInfoInputViewManager).getTe_fundiblextInput());
                        break;

                    case FundibleConfigs.Data_Action_Conta_fundiblect_Name:
                        nameList.add(baseInfoInputViewManager.getInp_fundibleut());
                        break;

                    case FundibleConfigs.Data_Action_Conta_fundiblect_Phone:
                        phoneList.add(baseInfoInputViewManager.getInp_fundibleut());
                        break;

                    default: dataMap.put(data.getParamName_fundible(),baseInfoInputViewManager.getInp_fundibleut().trim());
                }

            }

            //添加联系人信息
            if (!TextUtils.isEmpty(step_fundible.getContactParamName_fundible())){
                JSONArray jsonArray = new JSONArray();
                for (int i=0;i<relashipList.size();i++){
                    JSONObject jsonObject = new JSONObject();
                    try {
                        jsonObject.put("relation",relashipList.get(i).trim());
                        if (i<nameList.size()) jsonObject.put("fullName",nameList.get(i).trim());
                        if (i<phoneList.size()) jsonObject.put("mobile",phoneList.get(i).trim());
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    jsonArray.put(jsonObject);
                }
                dataMap.put(step_fundible.getContactParamName_fundible(),jsonArray.toString());
            }

            startLoading(this,"");
            OkHttpUtil.getInstance_fundible().uploadUserPrcsInfo(path_fundible,dataMap,this::onSubmitInfoResponse_fundible);

        };

    }

    /**
     * 法语区绑卡流程
     */
    private void initBindAccountProcess_Fr_fundible(LinearLayout groupLayout){

        View group2View = View.inflate(this,R.layout.view_fundible_item_bg_fundible_group,null);
        LinearLayout group2Layout = group2View.findViewById(R.id.vibg_layout_group);

        @SuppressLint("InflateParams") View bindAccountView = LayoutInflater.from(this).inflate(R.layout.item_fundible_process_bindaccount_fr,null);
        bindAccountViewManager_fundible = new BindAcco_fundibleuntViewM_fundibleanager_Fr(bindAccountView,null, page_fundible);
        group2Layout.addView(bindAccountView);

        nextBtn.setBackgroundResource(R.drawable.bg_gray_rc16dp);

        Acc_fundibleountLi_fundiblest_Fr.getInstance_fundible().setParseRunnable_fundible(() -> {
            if (Acc_fundibleountLi_fundiblest_Fr.getInstance_fundible().getBankAccountList_fundible().isEmpty())
                nextBtn.setBackgroundResource(R.drawable.bg_gray_rc16dp);
            else
                nextBtn.setBackgroundResource(R.drawable.bg_green_rc16dp);
        });

        nextBtnRunnable_fundible = () -> {

            if (bindAccountView == null) {
                onBackPressed();
                return;
            }

            if (Acc_fundibleountLi_fundiblest_Fr.getInstance_fundible().getBankAccountList_fundible().isEmpty()){//无绑卡提示
                new Kind_fundibleTip_fundibleDialog(this,
                        getString(R.string.kind_tips_no_bond_account),
                        getString(R.string.ok),
                        null).show();
                return;
            }

            if (Acc_fundibleountLi_fundiblest_Fr.getInstance_fundible().getBankAccountList_fundible().size()<2){
                new BindA_fundiblecc_fundibleountTipDialog_Fr(this,() -> {
                    //提交绑卡
                    new Subm_fundibleitAccount_fundibleDialog_Fr(this, this::onSubmitInfoResponse_fundible
                            , page_fundible).show();
                }).show();
                return;
            }

            new Subm_fundibleitAccount_fundibleDialog_Fr(this,() ->{
                //提交绑卡
                startLoading(this,"");
                OkHttpUtil.getInstance_fundible().requestUsPrcs(this::onProcessInfoResponse_fundible);
            }
            , page_fundible).show();

        };


        groupLayout.addView(group2View);
    }

    /**
     * 人脸流程
     */
    private void initFaceProcess_fundible(LinearLayout groupLayout){

        @SuppressLint("InflateParams") View faceView = LayoutInflater.from(this).inflate(R.layout.item_fundible_process_face,null);
        faceViewManager_fundible = new Face_fundibleViewM_fundibleanager(
                faceView,null, page_fundible,
                this::onProcessInfoResponse_fundible,
                () -> {if (faceViewManager_fundible !=null) faceViewManager_fundible.onPhotoUplo_fundibleadRespo_fundiblense();}
        );
        groupLayout.addView(faceView);

        nextBtnRunnable_fundible = () -> {
            if (faceView==null || faceViewManager_fundible ==null) {
                onBackPressed();
                return;
            }
            faceViewManager_fundible.nextCl_fundibleick(path_fundible);
        };

    }

    /**
     * Ocr流程
     */
    private void initOcrProcess_fundible(LinearLayout groupLayout){

        @SuppressLint("InflateParams") View ocrView = LayoutInflater.from(this).inflate(R.layout.item_fundible_process_ocr,null);
        ocrViewManager_fundible = new OcrVie_fundiblewMana_fundibleger(
                ocrView,null, page_fundible,
                this::onProcessInfoResponse_fundible,
                () -> {if (ocrViewManager_fundible !=null) ocrViewManager_fundible.onPhot_fundibleoUploadRe_fundiblesponse();}
        );
        groupLayout.addView(ocrView);

        ActivityResultLauncher<PickVisualMediaRequest> pickMedia_fundible = registerForActivityResult(new ActivityResultContracts.PickVisualMedia(), uri -> {
            if (uri != null && ocrViewManager_fundible != null) {
                ocrViewManager_fundible.pho_fundibletoUri = uri;
                ocrViewManager_fundible.imgPa_fundibleth = Image_fundibleConvert.get_fundibleBitmap_fundibleFileP_fundibleathFromURI(this, ocrViewManager_fundible.pho_fundibletoUri);
                ocrViewManager_fundible.onPh_fundibleot_fundibleoGet();
            }
        });

        ocrViewManager_fundible.set_fundiblePick_fundibleMe(pickMedia_fundible);

        nextBtnRunnable_fundible = () -> {
            if (ocrView == null || ocrViewManager_fundible ==null) {
                onBackPressed();
                return;
            }
            ocrViewManager_fundible.nextC_fundiblelick(path_fundible);
        };

    }

    /**
     * 添加信息输入控件
     * @param data 控件参数
     * @param relationships 联系人关系选项，可为空
     * @param groupLayout 控件容器
     */
    @SuppressLint("InflateParams")
    private void addInputView_fundible(Proces_fundiblesIn_fundiblefo_Data data, ArrayList<String> relationships, LinearLayout groupLayout){

        View inputView = null;

        switch (data.getAction_fundible()){

            case FundibleConfigs.Dat_fundiblea_Action_Select:
                inputView = LayoutInflater.from(this).inflate(R.layout.item_fundible_process_select,null);
                Sele_fundiblectViewMana selectViewManager = new Sele_fundiblectViewMana(inputView,data, page_fundible);
                processWidgetManagers_fundible.add(selectViewManager);
                break;

            case FundibleConfigs.Data_Action_DateP_fundibleick:
                inputView = LayoutInflater.from(this).inflate(R.layout.item_fundible_process_dateselect,null);
                DateS_fundibleelectVie_fundiblewManager datePickWidgetsManager = new DateS_fundibleelectVie_fundiblewManager(inputView,data, page_fundible);
                processWidgetManagers_fundible.add(datePickWidgetsManager);
                break;

            case FundibleConfigs.Data_Act_fundibleion_Contact_Relation://联系人-关系
                if (relationships!=null) data.setRelationships_fundible(relationships);
                inputView = LayoutInflater.from(this).inflate(R.layout.item_fundible_process_select,null);
                Sele_fundiblectViewMana contactSelectViewManager = new Sele_fundiblectViewMana(inputView,data, page_fundible);
                processWidgetManagers_fundible.add(contactSelectViewManager);
                break;

            case FundibleConfigs.Data_Act_fundibleion_GenderPick:
                inputView = LayoutInflater.from(this).inflate(R.layout.item_fundible_process_genderselect,null);
                Ge_fundiblenderSe_fundiblelectViewManager genderSelectViewManager = new Ge_fundiblenderSe_fundiblelectViewManager(inputView,data, page_fundible);
                processWidgetManagers_fundible.add(genderSelectViewManager);
                break;

            case FundibleConfigs.Data_Action_In_fundibleput:
            case FundibleConfigs.Data_Action_Conta_fundiblect_Name://联系人-名字
            case FundibleConfigs.Data_Action_Conta_fundiblect_Phone://联系人-电话
            default:
                inputView = LayoutInflater.from(this).inflate(R.layout.item_fundible_process_input,null);
                Input_fundibleViewMan_fundibleager inputWidgetsManager = new Input_fundibleViewMan_fundibleager(inputView,data, page_fundible);
                processWidgetManagers_fundible.add(inputWidgetsManager);
                break;
        }

        if (inputView!=null) groupLayout.addView(inputView);
    }



//-------------------------------------------权限处理-----------------------------------------------------------
    @Override
    public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {
        if (requestCode == PermissionCode_Camera){
            if (faceViewManager_fundible != null) faceViewManager_fundible.onCameraPer_fundiblemission_fundibleAgree();
            else if (ocrViewManager_fundible !=null) ocrViewManager_fundible.onCam_fundibleeraPermissio_fundiblenAgree();
        }
    }

    @Override
    public void onRationaleDenied(int requestCode) {}

    @Override
    public void onRationaleAccepted(int requestCode) {
        if (requestCode == PermissionCode_Camera)
            EasyPermissions.requestPermissions(this,
                    getString(R.string.launch_permissions_camera_fundible),
                    PermissionCode_Camera,
                    Manifest.permission.CAMERA);
    }

    @Override
    public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {
        if (requestCode == PermissionCode_Camera) {
            if (EasyPermissions.somePermissionPermanentlyDenied(this, perms))
                new AppSettingsDialog.Builder(this).build().show();
        }
    }


    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (ocrViewManager_fundible !=null && requestCode== OcrVie_fundiblewMana_fundibleger.Flag_StartCam_fundibleera){
            ocrViewManager_fundible.onPh_fundibleot_fundibleoGet();
        }
    }

    //-------------------------------------------响应-----------------------------------------------------------

    //信息上报成功响应
    public void onSubmitInfoResponse_fundible(){
        OkHttpUtil.getInstance_fundible().requestUsPrcs(this::onProcessInfoResponse_fundible);
    }

    public void onFetchFrAccountListResponse_fundible(){
        stopLoading();
        if (bindAccountViewManager_fundible !=null) bindAccountViewManager_fundible.refreshAcc_fundibleountList();
    }

    public void onProcessInfoResponse_fundible(){
        stopLoading();
        //无流程：跳转到申请页
        if (Pro_fundiblecessIn_fundiblefo.getInstance_fundible().getSteps_fundible().isEmpty())
            toApply();
            //有流程：跳转到流程页
        else startActivity(new Intent(this, Pro_fundiblecessAct_fundibleivity.class));

        finish();
    }


    //----------------------------------------提取基本信息中的全名----------------------------
    private void extractPersonalInfo(String key,String value){
        if (!currentStepName.equalsIgnoreCase(Process_Step_Personal)) return;
        switch (key){
            case "firstName":
                userNames[0] = value.trim();
                break;
            case "middleName":
                userNames[1] = value.trim();
                break;
            case "lastName":
                userNames[2] = value.trim();
                break;

        }

        if (!TextUtils.isEmpty(userNames[0]) && !TextUtils.isEmpty(userNames[2])){
            Pers_fundibleonalIn_fundiblefo.getInstance().setFullName(
                    userNames[0]+" "+(TextUtils.isEmpty(userNames[1]) ? "":userNames[1]+" ")+userNames[2]
            );
            Pers_fundibleonalIn_fundiblefo.getInstance().uploadUserInfo(null);
        }

    }



    @Override
    protected void onResume() {
        super.onResume();
        OkHttpUtil.getInstance_fundible().uploadEventPoint(page_fundible,"START","");
    }

    @Override
    protected void onPause() {
        super.onPause();
        OkHttpUtil.getInstance_fundible().uploadEventPoint(page_fundible,"END","");
    }

    //跳转到申请页
    private void toApply(){
        if (Pro_fundiblecessIn_fundiblefo.getInstance_fundible().isNewUser_fundible())
            startActivity(new Intent(this, LoanApplyActivity.class));
        else startActivity(new Intent(this, LoanApplyActivity_OldUser.class));

    }

    private int getStepImg(String step){
        switch (step){
            case Process_Step_Work: return R.drawable.img_process_workinfo;
            case Process_Step_Contact: return R.drawable.img_process_contactinfo;
            case Process_Step_Account: return R.drawable.img_process_accountinfo;
            case Process_Step_Personal:
            default:return R.drawable.img_process_personalinfo;
        }
    }

}